import axios from 'axios'
import globalConfig from '../config'
import qs from 'qs'
// create an axios instance
console.log(globalConfig)
const service = axios.create({
  // baseURL: globalConfig.requireUrl, // api 的 base_url
  timeout: 10000,
})

// 设置请求头
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

// 拦截请求头
service.interceptors.request.use(
  config => {
    if(config.method == 'post'){
      config.data = qs.stringify(config.data)
    }
    return config
  },
  error => {
    Promise.reject(error)
  }
)

// 拦截实体
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    return Promise.reject(error)
  }
)

export default service
